<!--
 * @Author: ChunLai
 * @Date: 2023-08-07 17:00:12
 * @LastEditTime: 2023-08-23 14:09:56
 * @Description: 条款文档阅读弹窗
 * @FilePath: \0.newInsure\src\views\sign\components\PdfFileDisplay.vue
-->
<template>
  <van-popup
    v-model="show"
    overlay-class="lay1_shark"
    position="bottom"
    round
    :close-on-click-overlay="false"
    :style="{ height: '90%' }"
    sticky
  >
    <div class="pop_read_mode">
      <div class="file_tt">
        {{ fileObj.fileName }}
      </div>
      <div class="file_cont">
        <div id="pdfReadBox"></div>
      </div>
      <div
        class="file_btn"
        :class="disabled ? 'disabled' : ''"
        @click="hasReadFile"
      >
        {{ btnTxt }}
      </div>
    </div>
  </van-popup>
</template>

<script>
import { pdfJs } from '@/utils/pdfh5';
export default {
  name: 'PdfFileDisplay',
  data() {
    return {
      show: false,
      disabled: false,
      fileObj: {},
      btnTxt: '我已阅读并知悉',
      timeOut: null,
    };
  },
  components: {},
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    initModule(item) {
      this.show = true;
      this.fileObj = item;
      let that = this;
      if (window.Pdfh5) {
        return that.initPdf();
      }
      pdfJs(function (res) {
        that.initPdf();
      });
    },
    hasReadFile() {
      if (this.fileObj.mustRead && this.fileObj.mustRead == '1') {
        if (this.disabled) return;
        this.$emit('readHad', this.fileObj.fileName);
      }
      this.show = false;
    },
    initPdf() {
      this.$nextTick(() => {
        this.pdfh5 = new Pdfh5('#pdfReadBox', {
          pdfurl: this.fileObj.fileUrl,
        });
        // this.countDown();
        // 监听完成事件
        this.pdfh5.on('complete', function (status, msg, time) {});
      });
    },
    countDown() {
      this.btnTxt = '我已阅读并知悉';
      this.disabled = true;
      clearInterval(this.timeOut);
      let i = 5;
      this.timeOut = setInterval(() => {
        i--;
        if (i <= 0) {
          //当时间小于等于0秒的时候让空间可用
          this.disabled = false;
          clearInterval(this.timeOut);
          this.btnTxt = '我已阅读并知悉';
        } else {
          //当时间还不够的时候继续锁定
          this.btnTxt = '我已阅读并知悉' + i;
        }
      }, 1000);
    },
  },
};
</script>

<style lang="less" scoped>
.pop_read_mode {
  height: 100%;
  padding: 0 12px;

  .file_tt {
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
  .file_cont {
    height: calc(100% - 100px);
    padding: 10px 0;
    overflow: hidden;
    overflow-y: scroll;
  }
  .file_btn {
    height: 40px;
    line-height: 40px;
    font-size: 18px;
    color: #ffffff;
    text-align: center;
    border-radius: 20px;
    margin-top: 5px;
    background: linear-gradient(90deg, #ff442b 0%, #cb1800 100%);
    &.disabled {
      background: none;
      background-color: #eee;
    }
  }
}
</style>
